/*********************\
* Author:Dzlua
* QQ:505544956
* Time:2017/04/16
\**********************/
#include "LuaTreeNode.h"

#define CObjPtr ((CTreeNodeUI*)m_cobj)

namespace DuiLib {

void LuaTreeNode::Invalidate()
{
    CObjPtr->Invalidate();
}

bool LuaTreeNode::Select(bool bSelect )
{
    return CObjPtr->Select(bSelect);
}

bool LuaTreeNode::SelectMulti(bool bSelect)
{
    return CObjPtr->SelectMulti(bSelect);
}

int LuaTreeNode::Add(LuaState *L)
{
    LuaStack args(L);
    bool bRet = false;
    CControlUI* ctrl = (CControlUI*)LuaHelperNS::GetCObjectData(args[2]);
    bRet = CObjPtr->Add(ctrl);
    L->PushBoolean(bRet);
    return 1;
}

int LuaTreeNode::AddAt(LuaState *L)
{
    LuaStack args(L);
    bool bRet = false;
    if (args[3].IsInteger()) {
        CControlUI* ctrl = (CControlUI*)LuaHelperNS::GetCObjectData(args[2]);
        bRet = CObjPtr->AddAt(ctrl, args[3].GetInteger());
    }
    L->PushBoolean(bRet);
    return 1;
}

int LuaTreeNode::Remove(LuaState *L)
{
    LuaStack args(L);
    bool bRet = false;
    CControlUI* ctrl = (CControlUI*)LuaHelperNS::GetCObjectData(args[2]);
    bRet = CObjPtr->Remove(ctrl);
    L->PushBoolean(bRet);
    return 1;
}

void LuaTreeNode::SetVisibleTag(bool _IsVisible)
{
    return CObjPtr->SetVisibleTag(_IsVisible);
}

bool LuaTreeNode::GetVisibleTag()
{
    return CObjPtr->GetVisibleTag();
}

int LuaTreeNode::SetItemText(LuaState *L)
{
    LuaStack args(L);
    SDTString str = LuaHelperNS::GetTString(args[2]);
    CObjPtr->SetItemText(str.c_str());
    return 0;
}

int LuaTreeNode::GetItemText(LuaState *L)
{
    SDTString str = CObjPtr->GetItemText().GetData();
    LuaHelperNS::PushTString(L, str);
    return 1;
}

void LuaTreeNode::CheckBoxSelected(bool _Selected)
{
    CObjPtr->CheckBoxSelected(_Selected);
}

bool LuaTreeNode::IsCheckBoxSelected()
{
    return CObjPtr->IsCheckBoxSelected();
}

bool LuaTreeNode::IsHasChild()
{
    return CObjPtr->IsHasChild();
}

long LuaTreeNode::GetTreeLevel()
{
    return CObjPtr->GetTreeLevel();
}

int LuaTreeNode::AddChildNode(LuaState *L)
{
    LuaStack args(L);
    CTreeNodeUI* ctrl = (CTreeNodeUI*)LuaHelperNS::GetCObjectData(args[2]);
    bool bRet = CObjPtr->AddChildNode(ctrl);
    L->PushBoolean(bRet);
    return 1;
}

int LuaTreeNode::RemoveAt(LuaState *L)
{
    LuaStack args(L);
    CTreeNodeUI* ctrl = (CTreeNodeUI*)LuaHelperNS::GetCObjectData(args[2]);
    bool bRet = CObjPtr->RemoveAt(ctrl);
    L->PushBoolean(bRet);
    return 1;
}

int LuaTreeNode::SetParentNode(LuaState *L)
{
    LuaStack args(L);
    CTreeNodeUI* ctrl = (CTreeNodeUI*)LuaHelperNS::GetCObjectData(args[2]);
    CObjPtr->SetParentNode(ctrl);
    return 0;
}

int LuaTreeNode::GetParentNode(LuaState *L)
{
    CTreeNodeUI* ctrl = CObjPtr->GetParentNode();
    LuaHelperNS::PushCObj(L, ctrl);
    return 1;
}

long LuaTreeNode::GetCountChild()
{
    return CObjPtr->GetCountChild();
}

int LuaTreeNode::SetTreeView(LuaState *L)
{
    LuaStack args(L);
    CTreeViewUI* ctrl = (CTreeViewUI*)LuaHelperNS::GetCObjectData(args[2]);
    CObjPtr->SetTreeView(ctrl);
    return 0;
}

int LuaTreeNode::GetTreeView(LuaState *L)
{
    CTreeViewUI* ctrl = CObjPtr->GetTreeView();
    LuaHelperNS::PushCObj(L, ctrl);
    return 1;
}

int LuaTreeNode::GetChildNode(LuaState *L)
{
    LuaStack args(L);
    int index = LuaHelperNS::GetInt(args[2], -1);
    CTreeNodeUI* ctrl = CObjPtr->GetChildNode(index);
    LuaHelperNS::PushCObj(L, ctrl);
    return 1;
}

void LuaTreeNode::SetVisibleFolderBtn(bool _IsVisibled)
{
    CObjPtr->SetVisibleFolderBtn(_IsVisibled);
}

bool LuaTreeNode::GetVisibleFolderBtn()
{
    return CObjPtr->GetVisibleFolderBtn();
}

void LuaTreeNode::SetVisibleCheckBtn(bool _IsVisibled)
{
    CObjPtr->SetVisibleCheckBtn(_IsVisibled);
}

bool LuaTreeNode::GetVisibleCheckBtn()
{
    return CObjPtr->GetVisibleCheckBtn();
}

void LuaTreeNode::SetItemTextColor(DWORD _dwItemTextColor)
{
    CObjPtr->SetItemTextColor(_dwItemTextColor);
}

DWORD LuaTreeNode::GetItemTextColor()
{
    return CObjPtr->GetItemTextColor();
}

void LuaTreeNode::SetItemHotTextColor(DWORD _dwItemHotTextColor)
{
    CObjPtr->SetItemHotTextColor(_dwItemHotTextColor);
}

DWORD LuaTreeNode::GetItemHotTextColor()
{
    return CObjPtr->GetItemHotTextColor();
}

void LuaTreeNode::SetSelItemTextColor(DWORD _dwSelItemTextColor)
{
    CObjPtr->SetSelItemTextColor(_dwSelItemTextColor);
}

DWORD LuaTreeNode::GetSelItemTextColor()
{
    return CObjPtr->GetSelItemTextColor();
}

void LuaTreeNode::SetSelItemHotTextColor(DWORD _dwSelHotItemTextColor)
{
    CObjPtr->SetSelItemHotTextColor(_dwSelHotItemTextColor);
}

DWORD LuaTreeNode::GetSelItemHotTextColor()
{
    return CObjPtr->GetSelItemHotTextColor();
}

int LuaTreeNode::GetTreeIndex()
{
    return CObjPtr->GetTreeIndex();
}

int	LuaTreeNode::GetNodeIndex()
{
    return CObjPtr->GetNodeIndex();
}

SDLUA_BEGIN_REGISTER(LuaTreeNode, TreeNode, ListContainerElement)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, Invalidate, Invalidate)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, Select, Select)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, SelectMulti, SelectMulti)

    SDLUA_REGISTER_FUN_LUA(LuaTreeNode, Add, Add)
    SDLUA_REGISTER_FUN_LUA(LuaTreeNode, AddAt, AddAt)
    SDLUA_REGISTER_FUN_LUA(LuaTreeNode, Remove, Remove)

    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, SetVisibleTag, SetVisibleTag)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, GetVisibleTag, GetVisibleTag)
    SDLUA_REGISTER_FUN_LUA(LuaTreeNode, SetItemText, SetItemText)
    SDLUA_REGISTER_FUN_LUA(LuaTreeNode, GetItemText, GetItemText)
    
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, CheckBoxSelected, CheckBoxSelected)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, IsCheckBoxSelected, IsCheckBoxSelected)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, IsHasChild, IsHasChild)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, GetTreeLevel, GetTreeLevel)
    SDLUA_REGISTER_FUN_LUA(LuaTreeNode, AddChildNode, AddChildNode)
    SDLUA_REGISTER_FUN_LUA(LuaTreeNode, RemoveAt, RemoveAt)
    SDLUA_REGISTER_FUN_LUA(LuaTreeNode, SetParentNode, SetParentNode)
    SDLUA_REGISTER_FUN_LUA(LuaTreeNode, GetParentNode, GetParentNode)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, GetCountChild, GetCountChild)
    SDLUA_REGISTER_FUN_LUA(LuaTreeNode, SetTreeView, SetTreeView)
    SDLUA_REGISTER_FUN_LUA(LuaTreeNode, GetTreeView, GetTreeView)
    SDLUA_REGISTER_FUN_LUA(LuaTreeNode, GetChildNode, GetChildNode)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, SetVisibleFolderBtn, SetVisibleFolderBtn)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, GetVisibleFolderBtn, GetVisibleFolderBtn)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, SetVisibleCheckBtn, SetVisibleCheckBtn)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, GetVisibleCheckBtn, GetVisibleCheckBtn)

    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, SetItemTextColor, SetItemTextColor)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, GetItemTextColor, GetItemTextColor)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, SetItemHotTextColor, SetItemHotTextColor)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, GetItemHotTextColor, GetItemHotTextColor)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, SetSelItemTextColor, SetSelItemTextColor)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, GetSelItemTextColor, GetSelItemTextColor)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, SetSelItemHotTextColor, SetSelItemHotTextColor)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, GetSelItemHotTextColor, GetSelItemHotTextColor)
    
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, GetTreeIndex, GetTreeIndex)
    SDLUA_REGISTER_FUN_CPP(LuaTreeNode, GetNodeIndex, GetNodeIndex)
SDLUA_END_REGISTER

SDLUA_BEGIN_UNREGISTER(LuaTreeNode, TreeNode)
SDLUA_END_UNREGISTER(TreeNode)

}

#undef CObjPtr